package com.service;

import com.dao.userdao.PersonalCenter;
import com.pojo.User;
import com.pojo.VerifyUser;
import com.util.CookieUtil;
import com.util.TokenUtil;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

public class UploadHead {
      public static void upload(HttpServletRequest req,String headpicture) throws IOException {
          Cookie cookie= CookieUtil.findCookie("Token",req.getCookies());
          String token=cookie.getValue();
          VerifyUser verifyUser= TokenUtil.get(token);
          String userid=verifyUser.getUserName();
          User user=new User();
          String is_mailbox="^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
          if(userid.matches(is_mailbox))
          {
              user.setMailbox(userid);
          }else{
              user.setUsername(userid);
          }
          user.setHeadpicture(headpicture);
          PersonalCenter.update_user_info(user);
      }


}
